package zuoye4;

import java.io.*;
import java.util.*;

public class commodity {
	public static void main(String[] args) {
		File f = new File("D:\\计算机\\大二上\\文件\\Pro5\\src\\zuoye4\\price.txt");
		
		int count = 0;
		double sum = 0, price = 0;
		
		try {
			Scanner sc = new Scanner(f);
			sc.useDelimiter("[^0123456789.]+");
			while(sc.hasNext()) {
				price = sc.nextDouble();
				count++;
				sum += price;
				System.out.println(price);
			}
			double aver = sum/count;
			String str = String.format("%.3f", aver);
			System.out.println("平均价格：" + str);
			
			OutputStream fos = new FileOutputStream(f, true);
		    OutputStreamWriter ior = new OutputStreamWriter(fos);
		    BufferedWriter br = new BufferedWriter(ior);
		    
	        br.newLine();
		    br.write("平均价格：" + str + "元/台");
		    
		    br.close();
		    
		}catch(Exception exp) {
			System.out.println(exp);
		}
	}
}
